package com.example.video.controller;

import com.example.video.common.Result;
import com.example.video.entity.OuterAccount;
import com.example.video.service.impl.OuterAccountServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author qiusuyang
 * @since 2024-04-13
 */
@Controller
@RequestMapping("/outerAcount")
public class OuterAcountController {

    @Resource
    private OuterAccountServiceImpl outerAcountService;

    /**
     * @param item 修改或添加的数据
     * @return 是否成功修改或添加
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Boolean> saveItem(OuterAccount item) {
        Result<Boolean> rs = new Result<>();
        Boolean flag = outerAcountService.save(item);
        rs.setData(flag);
        if (flag) {
            rs.setCode(200);
            rs.setMsg("成功");
        } else {
            rs.setCode(500);
            rs.setMsg("失败");
        }
        return rs;
    }

    /**
     * @param id 要删除数据的id
     * @return 是否删除成功
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Boolean> deleteItem(Integer id) {
        Result<Boolean> rs = new Result<>();
        Boolean flag = outerAcountService.delete(id);
        rs.setData(flag);
        if (flag) {
            rs.setCode(200);
            rs.setMsg("成功");
        } else {
            rs.setCode(500);
            rs.setMsg("失败");
        }
        return rs;
    }




}
